import {
  UserInfo,
  LoginPrams,
  UpdateMemberInfoParams,
  UpdateMemberOneParams,
  UpdatePasswordParams,
  UpdateMobileParams,
  UpdateEmailParams,
  RegisterParams,
  BindEmailParams,
  BindPhoneParams,
  EmailRecoverPasswordParams,
  RegisterResult,
  MemberInfo,
} from "./../types/member.d";

import http from "../utils/http";
import { useMemberStore } from "../store";

// 手机号登录
export const postLogin = (data: LoginPrams) => {
  return http<UserInfo>({
    url: "Member/login",
    method: "POST",
    data,
  });
};

// 邮箱登录
export const postEmailLogin = (data: LoginPrams) => {
  return http<UserInfo>({
    url: "Member/email_login",
    method: "POST",
    data,
  });
};

// 手机号注册
export const postPhoneRegister = (data: RegisterParams) => {
  return http<RegisterResult>({
    url: "Member/register",
    method: "POST",
    data,
  });
};

// 邮箱注册
export const postEmailRegister = (data: RegisterParams) => {
  return http<RegisterResult>({
    url: "Member/register_email",
    method: "POST",
    data,
  });
};

// 绑定邮箱
export const postBindEmail = (data: BindEmailParams) => {
  return http<any>({
    url: "Member/bind_email",
    method: "POST",
    data,
  });
};

// 绑定邮箱
export const postBindMobile = (data: BindPhoneParams) => {
  return http<any>({
    url: "Member/bind_mobile",
    method: "POST",
    data,
  });
};

// 邮箱找回密码
export const postEmailRecoverPassword = (data: EmailRecoverPasswordParams) => {
  return http<any>({
    url: "Member/forget_password_email",
    method: "POST",
    data,
  });
};

// 邮箱找回密码
export const postMobileRecoverPassword = (data: EmailRecoverPasswordParams) => {
  return http<any>({
    url: "Member/forget_password",
    method: "POST",
    data,
  });
};

// 根据单一字段名修改数据
export const postUpdateMemberOne = (data: UpdateMemberOneParams) => {
  return http<any>({
    url: "Member/update_one",
    method: "POST",
    data,
  });
};

// 修改密码
export const postUpdatePassword = (data: UpdatePasswordParams) => {
  return http<any>({
    url: "Member/update_password",
    method: "POST",
    data,
  });
};

// 修改手机号
export const postUpdateMobile = (data: UpdateMobileParams) => {
  return http<any>({
    url: "Member/update_mobile",
    method: "POST",
    data,
  });
};

// 修改邮箱
export const postUpdateEmail = (data: UpdateEmailParams) => {
  return http<any>({
    url: "Member/update_email",
    method: "POST",
    data,
  });
};

// 修改个人信息
export const postUpdateMemberInfo = (data: UpdateMemberInfoParams) => {
  return http<any>({
    url: "Member/update_information",
    method: "POST",
    data,
  });
};

// 获取个人信息
export const postMemberInfo = () => {
  return http<MemberInfo>({
    url: "Member/my",
    method: "POST",
  });
};

// 下载简历
export const postDownloadPdf = (member_id: number) => {
  return http<any>({
    url: "MemberPart6/pdfDown",
    method: "POST",
    data: {
      member_id,
    },
  });
};

// 查询可下载简历次数
export const postDownloadPdfCount = () => {
  const { profile } = useMemberStore();
  return http<any>({
    url: "member/logNum",
    method: "POST",
    data: {
      member_id: profile?.id,
    },
  });
};

// 平台颁发证书
export const platformIssuingCert = () => {
  const { profile } = useMemberStore();
  return http<any>({
    url: "ProfessionMaterial/all",
    method: "POST",
    data: {
      member_id: profile?.id,
    },
  });
};

// 站内消息
export const postUserMessageList = (_data) => {
  let member_id = useMemberStore().profile?.id;
  return http<any[]>({
    url: "instation/index",
    method: "POST",
    data: {
      ..._data,
      member_id,
    },
  });
};

// 站内消息未读
export const postUserMessageNoReadCount = () => {
  let member_id = useMemberStore().profile?.id;
  return http<any[]>({
    url: "instation/count",
    method: "POST",
    data: {
      member_id,
    },
  });
};
